package org.boyan.cases;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.boyan.entity.cases.NonFunctionalDemand;
import org.boyan.utils.ExcelExportUtils;
import org.boyan.utils.ExcelUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class NonFunctionalDemandToExcel {

    public static void exportNonFunctionalDemand(File file, NonFunctionalDemand nonFunctionalDemand) throws IOException {
        String fileName = file.getName();
        Workbook workbook = null;
        InputStream in = null;
        in = new FileInputStream(file);
        if (ExcelUtils.judegExcelEdition(fileName)) {
            workbook = new XSSFWorkbook(in);
        } else {
            workbook = new HSSFWorkbook(in);
        }
        Sheet sheet = workbook.getSheetAt(2);
        sheet.getRow(0).getCell(1).setCellValue(nonFunctionalDemand.getTransServerTime());
        sheet.getRow(0).getCell(3).setCellValue(nonFunctionalDemand.getConcurrencyUserAmount());
        sheet.getRow(1).getCell(1).setCellValue(nonFunctionalDemand.getResponseTime());
        sheet.getRow(1).getCell(3).setCellValue(nonFunctionalDemand.getTpsMaximum());
        sheet.getRow(2).getCell(1).setCellValue(nonFunctionalDemand.getDateQueryRange());
        sheet.getRow(2).getCell(3).setCellValue(nonFunctionalDemand.getSingleQueryRange());
        sheet.getRow(3).getCell(1).setCellValue(nonFunctionalDemand.getPaginationViewAmount());
        sheet.getRow(3).getCell(3).setCellValue(nonFunctionalDemand.getDailyTransAmount());
        int printFlag = nonFunctionalDemand.getPrintFlag();
        if (printFlag == 1) {
            sheet.getRow(4).getCell(1).setCellValue("是");
            sheet.getRow(4).getCell(3).setCellValue(nonFunctionalDemand.getCreateFileRange());
        } else {
            sheet.getRow(4).getCell(1).setCellValue("否");
        }
        int calculateFlag = nonFunctionalDemand.getCalculateFlag();
        if (calculateFlag == 1) {
            sheet.getRow(5).getCell(1).setCellValue("是");
            sheet.getRow(5).getCell(3).setCellValue(nonFunctionalDemand.getCalculateDescription());
        } else {
            sheet.getRow(5).getCell(1).setCellValue("否");
        }
        ExcelExportUtils.writeWorkbook(workbook,file);
        workbook.close();
        in.close();
    }
}
